package com.openingedu.mba.service;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;

import com.j256.ormlite.stmt.QueryBuilder;
import com.openingedu.mba.persist.DataHelper;
import com.openingedu.mba.persist.DbMessage;

public class MessageService {

	/**
	 * 查询所有消息
	 * @param context
	 * @param dataHelper
	 * @return 
	 */
	public synchronized List<DbMessage> listMessage(Context context) {
		DataHelper dataHelper = new DataHelper(context);
		List<DbMessage> messageList = null;
		try {
			QueryBuilder<DbMessage, Long> queryBuilder = dataHelper.getDbMessageDao().queryBuilder();
			queryBuilder.orderBy("createTime", false);
			messageList = queryBuilder.query();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return messageList;
	}

	/**
	 * 修改Message为已读
	 * @param context
	 * @param message
	 */
	public void update(Context context, DbMessage message) {
		DataHelper dataHelper = new DataHelper(context);
		try {
			dataHelper.getDbMessageDao().update(message);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
